using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Collections;
using Q.Framework.WebControls;

namespace Q.Framework.WebCode
{
    public class CrudCodeDescritionStatusBasePage : MasterPageBase
    {
        public event EventHandler Save;
        public event EventHandler Delete;
        public event EventHandler New;
        public event EventHandler SetOtherProperties;
        public event EventHandler PreencherOutrasInformacoes;
        public event EventHandler SearchBusiness;
        public TextBox TxtCodigo;
        public QTextBox TxtDescricao;
        public Label LblDescricao;
        public RadioButtonList RblStatus;
        public String Status;
        public String NomeCampoDescritivo
        {
            get { return ViewState["nomeCampo"] as String; }
            set { ViewState["nomeCampo"] = value; }
        }

        protected override void OnInit(EventArgs e)
        {
            ViewState["nomeCampo"] = "Descricao";
            base.OnInit(e);
        }

        public GridView GrdResultado;
        public String Codigo;
        public String Descricao;

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            //if (!IsPostBack)
            //    GrdResultado.Columns.RemoveAt(GrdResultado.Columns.Count - 1);
        }

        private void MessageRecording()
        {
            if (DisplayMessageNewRecording)
                MessageBoxAndRedirect(MessageNewRecord, GetPage());
            //JavaScriptAdd.MessageBoxShowRedrect(this.Page, MessageNewRecord, GetPage());
        }

        protected void DoSave(object sender, EventArgs e)
        {
            SetOtherProperties(sender, e);
            Save(sender, e);
            MessageRecording();
        }

        protected void DoSearchBusiness(object sender, EventArgs e)
        {
            SearchBusiness(sender, e);
        }

        protected void DoPreencherOutrasInformacoes(object sender, EventArgs e)
        {
            PreencherOutrasInformacoes(sender, e);
        }

        private void MessageDeleteRecording()
        {
            if (DisplayMessageDeleteRecording)
            {
                if (DisplayMessageNewRecording)
                {
                    String page = GetPage();

                    if (Session["PageSearch"] != null)
                    {
                        page = Session["PageSearch"].ToString();
                        Session["PageSearch"] = null;
                    }

                    MessageBoxAndRedirect(MessageDeleteRecord, page);
                    //JavaScriptAdd.MessageBoxShowRedrect(this.Page, MessageDeleteRecord, GetPage());
                }
            }

        }

        protected void DoNew(object sender, EventArgs e)
        {
            New(sender, e);
        }

        protected void DoDelete(object sender, EventArgs e)
        {
            Delete(sender, e);
            MessageDeleteRecording();
        }

        private String GetPage()
        {
            return this.Page.Request.Url.Segments.Last();
        }
    }
}